package com.example.springbootwebadmin.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.springbootwebadmin.bean.User;
import com.example.springbootwebadmin.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import java.util.Arrays;
import java.util.List;

@Controller
public class TableController {
    @Autowired
    UserService userService;
    //要记得给每个页面都加Thymeleaf的名称空间
    @GetMapping("/basic_table")
    public String basic_table(){
        return "table/basic_table";
    }
    @GetMapping("/dynamic_table")
    public String dynamic_table(Model model){
        //动态遍历表格
//        List<User> users= Arrays.asList(new User("张三","44556"),
//                new User("张5","44556"),
//                new User("张6","44556"),
//                new User("张7","44556"));
//        model.addAttribute("users",users);

        //从数据库中查出user表中的用户进行展示
        List<User> users = userService.list();
        //分页查询方法,从请求参数中拿到页码
        Page<User> userPage = new Page<>(1, 2);//当前页码1，显示两条
        Page<User> page = userService.page(userPage, null);
        model.addAttribute("page",page);

        return "table/dynamic_table";
    }
    @GetMapping("/responsive_table")
    public String responsive_table(){
        return "table/responsive_table";
    }
    @GetMapping("/editable_table")
    public String editable_table(){
        return "table/editable_table";
    }
}
